package Work0604;

import java.io.*;
import java.util.Date;
import java.util.Properties;

/**
 * 
 * 1:baidu Properties的用法,给出案例
 * 
 * @author Y
 *
 */
public class PropertiesTest {

	public static void main(String[] args) throws Exception {
		// 存储
		Properties p = new Properties();
		File a = new File("C:\\Users\\Y\\Desktop\\北大青鸟课件\\北大青鸟作业\\test.properties");
		OutputStream o = new FileOutputStream(a);
		p.setProperty("黑猪", "yellowboss");
		p.setProperty("白猪", "soloPeter");
		p.setProperty("灰猪", "helloworld");
		p.setProperty("蓝猪", "yesModel");
		p.store(o, new Date().toString());
		o.close();

		// 读取
		InputStream j = new FileInputStream(a);
		InputStream i = new BufferedInputStream(j);
		Properties prop = new Properties();
		prop.load(i);
		String path = prop.getProperty("黑猪");// 由key得到valus
		System.out.println("黑猪-->" + path);
		i.close();
		j.close();
	}

}
